package com.anthonybennis.blender.client.pages.keyboard;

import com.anthonybennis.blender.client.Util;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
import com.googlecode.mgwt.ui.client.widget.panel.scroll.ScrollPanel;

/**
 * 
 * @author abennis
 */
public class TilePanel 
{
	private final Widget _modelTileContainer;
	private final Widget _editModeTileContainer;
	private final Widget _viewTileContainer;
	private final Widget _objectMode;
	private ScrollPanel _scrollPanel;

	public enum PANEL{GENERAL, VIEW, OBJECT,EDIT};

	/**
	 * Construcotr.
	 */
	public TilePanel(TileDescriptionPanel descriptionPanel)
	{
		/*
		 * Create all Tiles so there's no delay on first button click.
		 */
		TileContainer tileContainer = new TileContainer(descriptionPanel);
		_modelTileContainer = tileContainer.createWidget(PANEL.GENERAL);
		_editModeTileContainer = tileContainer.createWidget(PANEL.EDIT);
		_viewTileContainer = tileContainer.createWidget(PANEL.VIEW);
		_objectMode = tileContainer.createWidget(PANEL.OBJECT);
	}
	
	/**
	 * 
	 * @return
	 */
	public ScrollPanel create()
	{
		_scrollPanel = new ScrollPanel();
		
		String backgroundcolour = Util.RGBToHex(64, 64, 64);
		Util.setBackground(_scrollPanel, backgroundcolour);
		_scrollPanel.setSize("100%", "100%");
		
		return _scrollPanel;
	}
	
	/**
	 * 
	 * @param panel
	 */
	protected void show(PANEL panel)
	{
		Widget widget = null;
		
		switch (panel) 
		{
			case OBJECT:
			{	
				widget = _objectMode;
				break;
			}
			case EDIT:
			{					
				widget = _editModeTileContainer;
				
				break;
			}
			case VIEW:
			{
				widget = _viewTileContainer;	
				break;
			}
			default: // Model
			{
				widget = _modelTileContainer;
				break;
			}	
		}
		
		if (_scrollPanel.iterator().hasNext())
		{
			Widget currentWidget = _scrollPanel.iterator().next();
			_scrollPanel.remove(currentWidget);
		}
		
		_scrollPanel.add(widget);
	}
}